<?php
class ClassroomContent{
    protected $main_table = 'data_classroom_content';
	protected $main_id = 'crc_id';
	protected $db = null;
	
	public function __construct($db){
		$this->db=$db;
	}
   
	public function __destruct(){
		unset($this->db);
	}
	public function get_table_name(){
	    return $this->main_table;
	    
	}
	
	/**
	* 	insert ClassroomContent
	* 	@param array $data 
	* 	@return int affected count
	*/
	public function insert_data($data){
		if(!is_array($data))
		my_jump('输入的参数有误');
		$rows = $this->db->insert($this->main_table, $data);
		$insert_id = $this->db->getInsertId();
		return $insert_id;	
	}	
	
	/**
	* 	update ClassroomContent
	* 	@param array $data 
	* 	@param string $where 
	* 	@return int affected count
	*/
	public function update_data($data,$where){
		if(!is_array($data))
		my_jump('输入的参数有误');
		$result = $this->db->update($this->main_table,$data,$where);
		return $result;
	}
	
	/**
	* 	delete ClassroomContent
	* 	@param string $where 
	* 	@return int affected count
	*/
	public function del_data($id){//删除图片
	
		$where = $this->main_id."='".$id."'";
		$result = $this->db->delete($this->main_table,$where);
		return $result;
	}	
	
	/**
	* 	get ClassroomContent info
	* 	@param int $id 
	*	@param array/string $field
	* 	@return array one row data
	*/
	public function get_data_row($id,$field='*'){
		if(!intval($id))
		my_jump('输入的参数有误!');
		$sql = "SELECT ".$field." FROM ".$this->main_table." WHERE ".$this->main_id."='".intval($id)."' ";
		$data = $this->db->getRow($sql);
		return $data;
	}	
	
	/**
	* 	get ClassroomContent array
	* 	@param string $where
	* 	@return array data
	*/
	public function get_data_array($where,$order='goods_id DESC',$limit='10',$field='goods_id,goods_name,goods_photo'){
		$sql = "SELECT ".$field." FROM ".$this->main_table." WHERE ".$where." ORDER BY ".$order;
		if(intval($limit)){
			$sql .= " LIMIT ".$limit;
		}
		$data = $this->db->getAll($sql);
		return $data;
	}

	//获取微课堂的介绍数据
	public function get_introduce(){		
		$where = "crc_type = '1'";
		$order='crc_id DESC';	
		$field='crc_id,crc_title';
		$sql = "SELECT ".$field." FROM ".$this->main_table." WHERE ".$where." ORDER BY ".$order;		
		$temp_data = $this->db->getAll($sql);		
		$data = array();		
		if($temp_data){
			foreach ($temp_data as $k => $v) {							
				$data[$v['crc_id']] = $v['crc_title'];
			}
		}		
		return $data;
	}	

	//获取微课堂的讲师介绍
	public function get_teacher(){		
		$where = "crc_type = '2'";
		$order='crc_id DESC';	
		$field='crc_id,crc_title';
		$sql = "SELECT ".$field." FROM ".$this->main_table." WHERE ".$where." ORDER BY ".$order;		
		$temp_data = $this->db->getAll($sql);		
		$data = array();		
		if($temp_data){
			foreach ($temp_data as $k => $v) {							
				$data[$v['crc_id']] = $v['crc_title'];
			}
		}		
		return $data;
	}	


	//获取微课堂的课堂环境
	public function get_env(){		
		$where = "crc_type = '3'";
		$order='crc_id DESC';	
		$field='crc_id,crc_title';
		$sql = "SELECT ".$field." FROM ".$this->main_table." WHERE ".$where." ORDER BY ".$order;		
		$temp_data = $this->db->getAll($sql);		
		$data = array();		
		if($temp_data){
			foreach ($temp_data as $k => $v) {							
				$data[$v['crc_id']] = $v['crc_title'];
			}
		}		
		return $data;
	}	
	
}

?>